<?php
namespace Home\Controller;
use Think\Controller;
class LoginController extends Controller {
    //登录
    public function login($userid,$password){
        $User = M("User");
        $data = $User->where('userid = "'. $userid .'" AND password= "'.$password.'"')->find();
        if($data != null) {
            $status = true;
            $key = "aWjibm05Mj";
            $value = $userid."|".$password."|".get_client_ip();
            $session = $key."".base64_encode($value);
            S('adminUser',$userid,86400);
            S('adminPassword',$password,86400);
            cookie('loginSession',$session,86400);
            $this->ajaxReturn(true);
        }
        $this->ajaxReturn(false);
    }
    //判断登录状态（1为已登录，0为未登录）
    public function checkLogin(){
        if(cookie('loginSession')){
            $value = base64_decode(str_replace('aWjibm05Mj','',cookie('loginSession')));
            $sessionInfo = S('adminUser')."|".S('adminPassword')."|".get_client_ip();
            if($value == $sessionInfo) return 1;
        }
        return 0;
    }
}